﻿using Microsoft.EntityFrameworkCore;
using Wallpaper.Data.Base;
using Wallpaper.Data.Context;
using Wallpaper.Data.IDal;
using Wallpaper.Models.Entities;

namespace Wallpaper.Data.Dal
{
    public class CategoryDal : BaseDal<Category>, ICategoryDal
    {
        public CategoryDal(WallpaperDbContext dbContext) : base(dbContext)
        {
        }

        /// <summary>
        /// 判断父类名称是否存在
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public async Task<bool> ExistsByNameAsync(string name)
        {
            return await _dbSet.AnyAsync(c => c.Name == name.Trim()); 
        }



        public async Task<bool> ExistsByNameAsync(string name, string excludeId)
        {
            return await _dbSet.AnyAsync(c => c.Name == name.Trim() && c.Id != excludeId);
        }

    }
}
